

#  file = open(path, encoding='gb18030'）
# 
    # try:
    #     with open(filepath, "r",encoding="utf-8") as fp:
    #         # string=fp.read()

# "G:\多的\download\keystore"
# "D:\file\sameNameFiles\download.zip"
# "G:\movedAli\1.pdf"
# "G:\movedAli\air.jpg"

utf_8="utf-8"

check_list=["dist","title.txt","reposLinks.json","ruoyi.zip","Spider.zip",
            "psc.jpg","kaggle.json","kanZhunSalary.zip","images.zip",
            "hotel.sql","example.tar.gz","douban.zip","clipboard.png","Answer.txt","00000.png","archive.zip"
            ,"我爱我家.json","安居客.json","s","images.tar.gz","下载.jpg",
            "image.gif","image.svg","output0.png","下载.png","page.html","NaN.txt","train.csv","test.csv"
            ,"1.txt","content.txt","cmd.exe","s.png","s.webp","settings.xml","emqx.conf","Hello.txt","css.css"
            ,"jdl.jdl","keystore.p12","ppt.zip","main.ipynb","miku.jpg","下载","图标素材.txt","server.xml"
            ,"logo.png","s (1).png","list.json","sql.txt","src.rar","工作簿1.xlsx","未命名-2.xd","Title.pdf"
            ,"main.cpp","out.html","out.mhtml","README.md","附件2.docx","工作簿4.xlsx","国奖.mp4","creators_civitai_get.json"
            ,"creators_civitai_get_pages.json","github_search.json","issues.json","WalkTwo.json","test.py"
            ,'results.zip',"1.cpp","XML.zip","apiclient_cert.p12","nginx.conf","pwc.pdf","Untitled.zip"
            ,"后端工程师.pdf","缪奇鹏.pptx","缪奇鹏-Java.pdf","缪奇鹏 java开发.pdf","图标素材.json","图片1.png"
            ,"未命名的设计.png","未命名简历.pdf","值.csv","值.json","下载 (1)","新建 Microsoft Excel 工作表.xlsx"
            ,"apiclient_key.pem","demo-0.0.1-SNAPSHOT.jar","download-image-py.ipynb","windows.zip"
            ,"job.csv","job.json","mongo.jpg","newfit.sql","phoneFIle.txt","public.sql","style.less","vant.png"
            ,"zhihu.png","后端.pdf","未命名1.cpp","未命名1.exe","未命名-1.xd","plan.sql","t_article.sql"
            ,"zhihu.sql","Word.docx","application-prod.yaml","bgm.mp3","all_data.csv","ruoyi.sql"
            ,"Untitled (1).ipynb","动画.fbx","动画.blend","动画_2.fbx","新建文件夹.zip","新建文本文档.c"
            ,"src.zip","keystore","redis.conf","sources.list","url.mp3","图片.png","图片1.png","1.pdf"
            ,"application-dev.yml","application-starp.yml","article.sql","app-release-signed.apk"
            ,"download.zip","air.jpg","dhcpcd.conf","eyesight.sql","nginx","newfit_zjuiot.sql"
            ,"party_school.sql","raspi.list","url.html"]
# "G:\多的\download\redis.conf"
# "G:\movedAli\nginx"
# "G:\movedAli\未命名1.exe"
# "G:\movedAli\zhihu.sql"
# "G:\movedAli\url.html"
# "G:\movedAli\raspi.list"
# "G:\movedAli\party_school.sql"
# "G:\movedAli\plan.sql"
# "G:\movedAli\t_article.sql"
# "G:\movedAli\eyesight.sql"
# "G:\movedAli\newfit_zjuiot.sql"
# "G:\movedAli\dhcpcd.conf"
# "G:\movedAli\article.sql"
# "G:\多的\download\url.mp3"
# "G:\movedAli\app-release-signed.apk"
# "G:\movedAli\application-starp.yml"
# "G:\movedAli\application-dev.yml"
# "G:\多的\download\sources.list"
# "G:\多的\download\图片.png"
import os

import codecs
import sys
import time
import os
try:
    import string_util
except Exception as e:
    from top.starp.util import string_util

import pprint
import csv

import pandas as pd

import os
import shutil

def safe_move(src_path,moved_path):
    """
    存在的 os.path.exists(moved_path): 就不会移动了
    """
    # moved_path=os.path.join(moved_path_base,file_name_last)
    # moved_path=rf'D:\movedAli/{file_name_last}'
    if  os.path.exists(moved_path):
        print(moved_path,"存在了")
        return
    try:
        shutil.move(src_path,moved_path)
    except Exception as e:
        print(e)
        print("移动失败",src_path,moved_path)



def write_file(out_path,out_str,encoding=utf_8):
    # create_file_with_directory()
    
    # out_text_path=f"/file/img_links/all_list_img_links_{now_time_str}.txt"
    print("out_path",out_path)
    check_and_create_file_parent_dir(out_path)
    with open(out_path,"w",encoding=encoding) as fp:
        fp.write(out_str)


def move_file_括号(source_folder = rf"D:\download",destination_folder = rf"D:\file\sameNameFiles",do_move=False):
    pattern = r".*[(（](\d+)[)）].*"

    # 遍历源文件夹中的文件
    for filename in os.listdir(source_folder):
        if "录音" in filename:
            continue
        match = re.match(pattern, filename)
        if match:
            # 提取括号内的数字
            number = match.group(1)
            # 去掉括号和括号内的内容
            # new_filename = re.sub(pattern, "", filename)
            new_filename=filename_删掉括号(filename)
            print("filename",filename)
            print("new_filename",new_filename)
            
            # print(fild)
            # 构建目标文件路径
            # destination_path = os.path.join(destination_folder, new_filename)
            destination_path = os.path.join(destination_folder, filename)
            # filename kaggle_code_https___www.kaggle.com_code_mikufance_anything-v3-0-gen (3).html
            # 移动文件
            first_file_path=os.path.join(source_folder, new_filename)
            if os.path.exists(first_file_path):
                destination_path_first = os.path.join(destination_folder, new_filename)
                if do_move:
                    # shutil.move(first_file_path, destination_path_first)
                    safe_move(first_file_path,destination_path_first)
                # print("first_file_path",first_file_path)
                print(f"移动文件: {first_file_path} 到 {destination_path_first}")
                pass
            if do_move:
                # shutil.move(os.path.join(source_folder, filename), destination_path)
                safe_move(os.path.join(source_folder, filename),destination_path)
            print(f"移动文件: {filename} 到 {destination_path}")
            # moved_count += 1


def show_dir_big_dirs(base_dir):
    for i in os.listdir(base_dir):
        abs_path=os.path.join(base_dir,i)
        size=get_folder_size(abs_path)
        # print(f"{i} size:{size}")
        size_show=convert_size(size)
        mb_50=mb_size(50)
        if size>mb_50:
            print("========")
            print(abs_path)
            print(size_show)

def mb_size(mb_number):
    return mb_number*1024*1024

def disk_name_get(dir_name = r"D:\download"):

    # dir_name = r"D:\download"
    disk_name = os.path.splitdrive(dir_name)[0]
    # print(disk_name)
    return disk_name


def get_folder_size(folder_path):
    total_size = 0
    for path, _, files in os.walk(folder_path):
        for file in files:
            file_path = os.path.join(path, file)
            total_size += os.path.getsize(file_path)
    return total_size

# 示例用法
# folder_path = r'C:\path\to\folder'  # 要查看大小的文件夹路径

# size_in_bytes = get_folder_size(folder_path)
# size_in_kb = size_in_bytes / 1024
# size_in_mb = size_in_kb / 1024
# size_in_gb = size_in_mb / 1024

# print(f"Folder size: {size_in_bytes} bytes, {size_in_kb:.2f} KB, {size_in_mb:.2f} MB, {size_in_gb:.2f} GB")


def check_and_move_file(src,dst):
    # create_file_with_directory()
    check_and_create_file_parent_dir(dst)
    # shutil.move(src,dst)
    safe_move(src,dst)

def read_file(filepath,encoding="utf-8"):
    try:
        with open(filepath, "r",encoding=encoding) as fp:
            string=fp.read()
            return string
    except Exception as e:
        print(e)
        print("filepath")
        print(filepath)
        return None


def read_file_get_file(filepath,encoding="utf-8"):
    try:
        with open(filepath, "r",encoding=encoding) as fp:
            return fp
            # string=fp.read()
            # return string
    except Exception as e:
        print(e)
        print("filepath")
        print(filepath)
        return None

"""
st_mode: inode 保护模式
st_ino: inode 节点号。
st_dev: inode 驻留的设备。
st_nlink: inode 的链接数。
st_uid: 所有者的用户ID。
st_gid: 所有者的组ID。
st_size: 普通文件以字节为单位的大小；包含等待某些特殊文件的数据。
st_atime: 上次访问的时间。
st_mtime: 最后一次修改的时间。
st_ctime: 由操作系统报告的”ctime”。在某些系统上（如Unix）是最新的元数据更改的时间，在其它系统上（如Windows）是创建时间（详细信息参见平台的文档）。
————————————————
版权声明：本文为CSDN博主「月尽天明_」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。
原文链接：https://blog.csdn.net/huiyanshizhu/article/details/81277555
"""
def show_time(time_int):
    # time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(test_stat.st_mtime))
    return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time_int))
#     python 查看、修改文件属性_月尽天明_的博客-CSDN博客_python查看文件属性
# https://blog.csdn.net/huiyanshizhu/article/details/81277555


def decimal_places(num, places=2):
    return f'%.{places}f' %(num)

def show_stat_of_path(path):
    stat=os.stat(path)
    last_modify_time=show_time(stat.st_mtime)
    # last_modify_time=show_time(stat.st_uid)
    # s=show_time(stat.st_size)
    print("last_modify_time",last_modify_time)
    # st_ctime
    create_time=show_time(stat.st_ctime)
    print("create_time",create_time)
    size=stat.st_size
    # print(size,"",size/1000,"M",size/1000/1000,"G")

    # string_util.po
    string_util.decimal_places(size)
    # 小数点2位数 python str  
    print(string_util.decimal_places(size),"B, ",
          string_util.decimal_places(size/1000) ,"K,",
          string_util.decimal_places(size/1000/1000),"M,",
         string_util.decimal_places(size/1000/1000/1000) ,"G,")
    # print(size,"B",size/1000,"K",size/1000/1000,"M",size/1000/1000/1000,"G")

def look_front(filePath,front_idx=300):
    with open(filePath, "r",encoding="utf-8") as f:
        # data=f.read(300)
        data=f.read(front_idx)
    pprint.pprint(data)

def help_output(help_element,filename = 'help.txt'):
    # filename = 'help.txt'

    stdout = sys.stdout
    out_file = open(filename, 'w+',encoding='utf-8')
    sys.stdout = out_file

    help(help_element)
    out_file.flush()

    out_file.close()
    sys.stdout = stdout
# srcfile 需要复制、移动的文件   
# dstpath 目的地址



# 从一个路径 获取文件名 pytho 

def getAllFilesOfWalk(dir):
    """使用listdir循环遍历"""
    if not os.path.isdir(dir):
        print (dir)
        return
    dirlist = os.walk(dir)
    # print("dirlist")
    # print(dirlist)
    abs_path_list=[]
    for root, dirs, files in dirlist:
        for file in files:
            # if file == className+'.java':
            if "考试" in file:

                abs_path=os.path.join(root,file)
                # print(abs_path)
                # os.system('idea64 '+abs_path)
                abs_path_list.append(abs_path)

                # file_path_lst.append(abs_path)
    return abs_path_list


# def dd(records):
#     df=pd.DataFrame.from_records(records)
#  数据列名
def to_csv(datas,file_name,encoding='utf-8-sig',mode='w'):
    # header = ['name', 'age'],
    # # header = ['name', 'age'] #数据列名
    # datas = [{'name': 'Tony', 'age': 17},
    #         {'name': '李华', 'age': 21}] # 字典数据
    # python 写出 csv 某几列 
    # dict 的列表转化为 dateframe
    header=datas[0].keys()
    # pd.DataFrame.from_records(data)
# 
    # test.csv表示如果在当前目录下没有此文件的话，则创建一个csv文件
    # a表示以“追加”的形式写入，如果是“w”的话，表示在写入之前会清空原文件中的数据
    # newline是数据之间不加空行
    # encoding='utf-8'表示编码格式为utf-8，如果不希望在excel中打开csv文件出现中文乱码的话，将其去掉不写也行。
    with open(file_name,mode= mode, newline='',encoding=encoding) as f: 
        # f.write(codecs.BOM_UTF8)
        writer = csv.DictWriter(f,fieldnames=header) # 提前预览列名，当下面代码写入数据时，会将其一一对应。
        # writer.write(codecs.BOM_UTF8)
        writer.writeheader()  # 写入列名
        
        writer.writerows(datas) # 写入数据
    print("file_name",file_name)

def parent_directory(file_path):
        # 获取父路径
    parent_directory = os.path.dirname(file_path)

    # print(parent_directory)  # 输出父路径
    return parent_directory


import os

def remove_empty_dirs(folder):
    for fileName in os.listdir(folder):
        absPath=os.path.join(folder,fileName)
        if not os.path.isdir(absPath):
            continue
        if  os.listdir(absPath):
            # 有东西
            continue
        os.rmdir(absPath)




def scrawl_file_move_of_dir(from_dir_name=rf"H:\download",batch_files_dir=rf"H:\file\batch_files"):
    # "D:\download\baidu_https___www.baidu.com_s_tn=28114124_1_dg&wd=available%3A+expected+at+least+1+bean+which+qualifies+as+autowire+candidate.+Dependency+annotations%3A+%7B%40org.springframework.beans.factory.annotation.Autowired%28required%3Dtru.html"
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf"{batch_files_dir}/baidu",startswith="baidu_",ends_with=".html")
    # "D:\movedAli\baidu_https___www.baidu.com_s_tn=02003390_42_hao_pg&wd=com.mysql.jdbc.exceptions.jdbc4.CommunicationsException%3A+Communications+link+failure&ie=utf-8.html"
    # file_like_move(from_dir_name=from_dir_name,to_dir_name=rf"D:\bingDown",startswith="bingDown",ends_with=".html")
    # "D:\download\bingDown_https___www.bing.com_search_pglt=43&q=%E4%BD%A0%E6%9C%89%E4%BB%80%E4%B9%88+%E5%B3%B0%E5%93%A5&cvid=e7d919de1d214af69a491726e2d0b997&gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIGCAEQABhAMgYIAhAAGEAyBggDEAAYQDIGCAQQABhAMgYIBRAAGEAyB.html"
    # "D:\download\nowcoder (7).json"
    # "D:\download\biliAiPicDownBatch_2023_07_29_14_06_28.json"
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/biliAiPicDownBatch',startswith="biliAiPicDownBatch",ends_with=".json")
    # "D:\download\xhs_note_https___www.xiaohongshu.com_explore_650f0826000000001302fa90.json"
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/xhs_note',startswith="xhs_note",ends_with=".json")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/nowcoder',startswith="nowcoder",ends_with=".json")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf"{batch_files_dir}/bingDown",startswith="bingDown",ends_with=".html")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/taobao',startswith="taobao",ends_with=".json")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/boss_detail',startswith="boss_detail",ends_with=".html")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/boss_detail_json',startswith="boss_detail",ends_with=".json")
    # file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/boss_detail_json',startswith="boss_detail",ends_with=".html")
    # "D:\download\zhihu_ans_车祸,保险公司赔偿一部分,肇事者赔偿一部分,我应该先要到肇事者赔偿的一部分再签调解书吗_ (2).html"
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/newrank_detail_links',startswith="newrank_detail_links",ends_with=".json")
    # "D:\download\newrank_detail_links_https___xh.newrank.cn_account_rank_business_2023_11_29_16_11_28.json"
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/huggingface_main',startswith="huggingface_main",ends_with=".html")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/zhiPin_page',startswith="zhiPin_page",ends_with=".json")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/zhiPin_page_html',startswith="zhiPin_page",ends_with=".html")
    # "H:\download\zhiPin_page_pos_100212_4__2023_10_3_2_22_17.html"
    # "D:\download\zhi_lian_link_https___sou.zhaopin.com__jl=653&kw=%E4%BC%9A%E8%AE%A1&p=2_page_2_2023_10_15_9_20_55.json"
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/zhi_lian_link',startswith="zhi_lian_link",ends_with=".json")
    # "D:\download\zhihu_ans_孙红雷移民该不该受到指责_ (1).json"
    # "D:\download\csdn_https___blog.csdn.net_jonathan_joestar_article_details_127683254_ops_request_misc=%257B%2522request%255Fid%2522%253A%2522169069357916800188573440%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&r (1).html"
    # file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/zhihu_ans',startswith="zhihu_ans",ends_with=".html")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/zhihu_ans_html',startswith="zhihu_ans",ends_with=".html")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/bingDown',startswith="bingDown",ends_with=".html")
    # "H:\download\zhihu_ans_为什么星星不会说话_ (2).html"
    # "D:\download\bingDown_https___www.bing.com_search_q=%E7%AC%AC%E5%85%AB%E9%83%A8%3A%E7%95%B8%E5%BD%A2%E5%84%BF%E8%87%AD%E4%B8%8D%E8%A6%81%E8%84%B8%E7%A0%B4%E5%9D%8F%E6%A8%A1%E8%8C%83%E5%A5%BD%E5%AE%B6%E3%80%82&cvid=996f5f0c8d664d43baf481a84.html"
    # "H:\download\zhihu_ans_如何看待计算机专业_ (5).json"
    # "D:\download\zhihu_shouye_https___www.zhihu.com__2023_10_14_23_53_53.html"
    # "D:\download\zhihuArticle_https___zhuanlan.zhihu.com_p_89045700.html"
    # "D:\download\zhihu_ans_孙红雷移民该不该受到指责_ (5).html"
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/bili_cv',startswith="bili_cv",ends_with=".html")
    # "D:\download\bili_cv_https___www.bilibili.com_read_cv9063143_.html"
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/baidu_https',startswith="baidu_https",ends_with=".html")
    # "D:\download\baidu_https___www.baidu.com_s_tn=28114124_1_dg&wd=available%3A+expected+at+least+1+bean+which+qualifies+as+autowire+candidate.+Dependency+annotations%3A+%7B%40org.springframework.beans.factory.annotation.Autowired%28required%3Dtru.html"
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/bingDown',startswith="bingDown",ends_with=".html")
    # "D:\download\bingDown_https___www.bing.com_search_q=CondaHTTPError%3A+HTTP+000+CONNECTION+FAILED+for+url&cvid=7d0f543485b546cd9db819ef910e4dcf&gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIGCAEQRRg7MgYIAhBFGDrSAQcyODBqMGo0qAIAsAIA&FORM=ANAB01&PC=LCTS&mkt.html"
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/zhihu_ans',startswith="zhihu_ans",ends_with=".json")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/zhihuArticle',startswith="zhihuArticle",ends_with=".html")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/zhihu_shouye',startswith="zhihu_shouye",ends_with=".html")
    # "H:\download\boss_detail_8ce34440536c8a9b1Xx_39-9GVZW_C++图形工具链开发_idx_0.html"
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/zhi_lian_detail',startswith="zhi_lian_detail",ends_with=".json")
    # "H:\download\zhi_lian_detail_https___jobs.zhaopin.com_CCL1330365040J40448356013.htm_refcode=4019&srccode=401901&preactionid=8b0a11ab-eec5-4cb5-9e25-f019b24e97ef.json"
    # "H:\download\qianCheng_link_https___sou.zhaopin.com__jl=653&kw=%E5%90%8E%E6%9C%9F%E5%88%B6%E4%BD%9C&p=8_page_8_2023_10_10_11_37_34.json"
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/qianCheng',startswith="qianCheng",ends_with=".json")
    # "H:\download\bai_jia_hao_https___baijiahao.baidu.com_s_id=1776295522673189503&wfr=spider&for=pc (1).html"
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/zhihu_ans',startswith="zhihu_ans",ends_with=".json")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/csdn',startswith="csdn",ends_with=".html")
    # "H:\download\csdn_https___blog.csdn.net_jonathan_joestar_article_details_127181447_spm=1001.2014.3001.5502.html"/
    # "H:\download\wget_https___gitee.com_intern-resume_vite-resume (1).sh"
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/kaggle_code',startswith="kaggle_code",ends_with=".html")
    # "H:\download\kaggle_code_https___www.kaggle.com_code_mikufance_anything-v5-gen (2).html"
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/wget_https',startswith="wget_https",ends_with=".sh")
    # "D:\download\zhihuArticleDownMyPage_https___www.zhihu.com_people_lu-ming-xu-14_pins_2023_10_29_20_2_4.json"
    # "D:\download\newrank_detail_https___xh.newrank.cn_d_account_accountOverview_56f0e44eaed7587464e46339_2023_10_29_16_57_51.html"
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/zhihuArticleDownMyPage',startswith="zhihuArticleDownMyPage",ends_with=".json")
    # newrank_detail
    # "D:\download\nowcoderAns_idx_370.json"
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/nowcoderAns',startswith="nowcoderAns",ends_with=".json")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/cai_pan_wen_shu_page',startswith="cai_pan_wen_shu_page",ends_with=".json")
    # "D:\download\cai_pan_wen_shu_page_https___wenshu.court.gov.cn_website_wenshu_181217BMTKHNT2W0_index.html_pageId=976f5b992b344177ce13dddf3b8e8ec5&s21=%E5%8E%9F%E7%A5%9E_2023_10_30_13_55_48.json"
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/newrank_detail',startswith="newrank_detail",ends_with=".html")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/bai_jia_hao',startswith="bai_jia_hao",ends_with=".html")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/bingDown',startswith="bingDown",ends_with=".html")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/taobao',startswith="taobao",ends_with=".json")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/zhihu_ans',startswith="zhihu_ans",ends_with=".json")
    # "D:\download\zhihu_ans_未经对方同意，在朋友圈发对方朋友圈和聊天记录截图算侵犯对方隐私权吗？.json"
    # "D:\download\taobao_寿司_2023_12_2_21_45_50.json"
# shutil.rmtree(dir_name_base)
    # "D:\download\bingDown_https___www.bing.com_search_q=CondaHTTPError%3A+HTTP+000+CONNECTION+FAILED+for+url&cvid=7d0f543485b546cd9db819ef910e4dcf&gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIGCAEQRRg7MgYIAhBFGDrSAQcyODBqMGo0qAIAsAIA&FORM=ANAB01&PC=LCTS&mkt.html"


def get_relative_path(filePath = rf"D:\proj\brain\chat-brain\src\pages\Ta\index.tsx"):
    """
    Ta\index.tsx
    """
    
    # filePath = rf"D:\proj\brain\chat-brain\src\pages\Ta\index.tsx"

    # 获取父路径
    parent_directory = os.path.dirname(os.path.dirname(filePath))

    # 去掉前面的绝对路径
    relative_path = filePath.replace(parent_directory, "", 1).lstrip("\\/")

    print("relative_path")  # 输出相对路径
    print(relative_path)
    # Ta\index.tsx
    # Ta\index.tsx
    linux_path=win_path_to_linux_path(relative_path)
    return linux_path

def win_path_to_linux_path(win_path = r"D:\proj\brain\chat-brain\src\pages\Ta\index.tsx"):
    # win_path = r"D:\proj\brain\chat-brain\src\pages\Ta\index.tsx"

    linux_path = win_path.replace("\\", "/")

    # print(linux_path)  # 输出Linux路径
    return linux_path

# from glob import glob

# "D:\好活.txt"
 
def move_file(srcfile,dstpath):                       # 移动函数
    if not os.path.isfile(srcfile):
        print ("%s not exist!"%(srcfile))
    else:
        fpath,fname=os.path.split(srcfile)             # 分离文件名和路径
        if not os.path.exists(dstpath):
            os.makedirs(dstpath)                       # 创建路径
        abs_dst_path=os.path.join(dstpath,fname)
        # shutil.move(srcfile, dstpath + fname)          # 移动文件
        shutil.move(srcfile,abs_dst_path)  
        # print ("move %s -> %s"%(srcfile, dstpath + fname))
        print ("move %s -> %s"%(srcfile, abs_dst_path))

 
def move_file_no_add_dir(srcFilePath,dstDir):                       # 移动函数
    if not os.path.isfile(srcFilePath):
        print ("%s not exist!"%srcFilePath)
    else:
        filePath,fileName=os.path.split(srcFilePath)             # 分离文件名和路径
        if not os.path.exists(dstDir):
            os.makedirs(dstDir)                       # 创建路径
        abs_dst_path=os.path.join(dstDir,fileName)
        # shutil.move(srcfile, dstpath + fname)          # 移动文件
        print ("move %s -> %s"%(srcFilePath, abs_dst_path))
        try:
            shutil.move(srcFilePath,abs_dst_path)  
        except Exception as e:
            print(e)
            # print
            print('err abs_dst_path ',abs_dst_path,"srcfile ",srcFilePath)
        # print ("move %s -> %s"%(srcfile, dstpath + fname))
        # print ("move %s -> %s"%(srcfile, abs_dst_path))
 
# src_dir = './'
# dst_dir = './move/'                                    # 目的路径记得加斜杠
# src_file_list = glob(src_dir + '*')                    # glob获得路径下所有文件，可根据需要修改
# for srcfile in src_file_list:
#     mymovefile(srcfile, dst_dir)                       # 移动文件

def show_stat(stat):
    last_modify_time=show_time(stat.st_mtime)
    # last_modify_time=show_time(stat.st_uid)
    # s=show_time(stat.st_size)
    print("last_modify_time",last_modify_time)
    size=stat.st_size
    # print(size,"",size/1000,"M",size/1000/1000,"G")
    print(size,"B",size/1000,"K",size/1000/1000,"M",size/1000/1000/1000,"G")
    # st_size=250167437



encoding_list=['utf-8','gbk','gb18030',]


def read_file_try(filepath):
    for encoding in encoding_list:
        string=read_file(filepath,encoding=encoding)
        if string:
            return string

def taoBao_json_move():
    print("taoBao_json_move")
    dir_name=rf"D:\download"
    to_dir_name=rf"D:\taoBao"
    print(" from dir_name",dir_name)
    print("  to_dir_name",to_dir_name)
    for i in os.listdir(dir_name):
        # "D:\taoBao\taobao_ 杏仁_2023_2_6_8_43_5.json"
        if i.startswith("taobao") and i.endswith(".json"):
            abs_from_file=os.path.join(dir_name,i)
            abs_to_file=os.path.join(to_dir_name,i)
            if os.path.exists(abs_to_file):
                print("文件已存在",abs_to_file)
                continue
            shutil.move(abs_from_file,abs_to_file)  


def sch_24_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\24detail",startswith="school_24"):
    # "D:\download\school_24_detail_F6D395C961B601DEE0530A01001665F6_idx_34574.json"
    # dir_name=rf"D:\download"
    # to_dir_name=rf"D:\24detail"
    for i in os.listdir(dir_name):
        if i.startswith(startswith) and i.endswith(".json"):
            abs_from_file=os.path.join(dir_name,i)
            abs_to_file=os.path.join(to_dir_name,i)
            if os.path.exists(abs_to_file):
                print("文件已存在",abs_to_file)
                continue
            shutil.move(abs_from_file,abs_to_file)  
    print("to_dir_name",to_dir_name)


def file_like_move(from_dir_name=rf"D:\download",to_dir_name=rf"D:\24detail",startswith="school_24",ends_with=".json"):
    # "D:\download\school_24_detail_F6D395C961B601DEE0530A01001665F6_idx_34574.json"
    # dir_name=rf"D:\download"
    # to_dir_name=rf"D:\24detail"
    # os.path. 
    if not os.path.exists(from_dir_name):
        return
    # os.makedirs(to_dir_name,exist_ok=True)
    # os.makedirs(to_dir_name)
    for i in os.listdir(from_dir_name):
        if i.startswith(startswith) and i.endswith(ends_with):
            abs_from_file=os.path.join(from_dir_name,i)
            abs_to_file=os.path.join(to_dir_name,i)
            if os.path.exists(abs_to_file):
                print("文件已存在",abs_to_file)
                continue
            # shutil.move(abs_from_file,abs_to_file)  
            # move_file_no_add_dir(abs_from_file,abs_to_file)
            move_file_no_add_dir(abs_from_file,to_dir_name)
    print("to_dir_name",to_dir_name)

def starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\24detail",startswith="school_24"):
    file_like_move(dir_name,to_dir_name,startswith,ends_with=".json")
    # "D:\download\school_24_detail_F6D395C961B601DEE0530A01001665F6_idx_34574.json"
    # dir_name=rf"D:\download"
    # to_dir_name=rf"D:\24detail"
    # os.path. 
    # os.makedirs(to_dir_name,exist_ok=True)
    # # os.makedirs(to_dir_name)
    # for i in os.listdir(dir_name):
    #     if i.startswith(startswith) and i.endswith(".json"):
    #         abs_from_file=os.path.join(dir_name,i)
    #         abs_to_file=os.path.join(to_dir_name,i)
    #         if os.path.exists(abs_to_file):
    #             print("文件已存在",abs_to_file)
    #             continue
    #         shutil.move(abs_from_file,abs_to_file)  
    # print("to_dir_name",to_dir_name)


# mai 

def remove_tao_bao_dirs():
    taoBao_dir_name=rf"D:\taoBao"
    # for i in os.listdir(dir_name):
    #     # "D:\taoBao\taobao_ 杏仁_2023_2_6_8_43_5.json"
    #     if i.startswith("taobao") and i.endswith(".json"):
    #         abs_from_file=os.path.join(dir_name,i)
    #         abs_to_file=os.path.join(to_dir_name,i)
    #         shutil.move(abs_from_file,abs_to_file)  
    #         # move_file(abs_from_dir,abs_to_dir)
    #         # D:\taoBao

    # D:\taoBaoOut
    taoBaoOut_dir_name=rf"D:\taoBaoOut"
    # 'D:\\taoBao\\taobao_ 杏仁_2023_3_18_8_47_21.json'
    # res=os.removedirs('D:\\taoBao\\taobao_ 杏仁_2023_3_18_8_47_21.json')
    # print("res",res)
    for i in os.listdir(taoBao_dir_name):
        # if 
        # print(i)
        abs_json_dir_path_from=os.path.join(taoBao_dir_name,i)
        
        if os.path.isdir(abs_json_dir_path_from):
            abs_json_path=os.path.join(taoBao_dir_name,i,i)
            abs_json_path_to=os.path.join(taoBaoOut_dir_name,i)
            # shutil.move(abs_json_path,abs_json_path_to)  
            # print("abs_json_path",)
            # print(abs_json_path,abs_json_path_to)
            # os.remove(abs_json_dir_path_from)
            # os.remove(abs_json_dir_path_from)
            os.removedirs(abs_json_dir_path_from)
            print(abs_json_dir_path_from)

def taobao_move_out():
    taoBao_dir_name=rf"D:\taoBao"
    # for i in os.listdir(dir_name):
    #     # "D:\taoBao\taobao_ 杏仁_2023_2_6_8_43_5.json"
    #     if i.startswith("taobao") and i.endswith(".json"):
    #         abs_from_file=os.path.join(dir_name,i)
    #         abs_to_file=os.path.join(to_dir_name,i)
    #         shutil.move(abs_from_file,abs_to_file)  
    #         # move_file(abs_from_dir,abs_to_dir)
    #         # D:\taoBao

    # D:\taoBaoOut
    taoBaoOut_dir_name=rf"D:\taoBaoOut"
    # 'D:\\taoBao\\taobao_ 杏仁_2023_3_18_8_47_21.json'
    # res=os.removedirs('D:\\taoBao\\taobao_ 杏仁_2023_3_18_8_47_21.json')
    # print("res",res)
    for i in os.listdir(taoBao_dir_name):
        # if 
        # print(i)
        abs_json_dir_path_from=os.path.join(taoBao_dir_name,i)
        
        if os.path.isdir(abs_json_dir_path_from):
            abs_json_path=os.path.join(taoBao_dir_name,i,i)
            abs_json_path_to=os.path.join(taoBaoOut_dir_name,i)
            # shutil.move(abs_json_path,abs_json_path_to)  
            # print("abs_json_path",)
            # print(abs_json_path,abs_json_path_to)
            # os.remove(abs_json_dir_path_from)
            # os.remove(abs_json_dir_path_from)
            os.removedirs(abs_json_dir_path_from)
            print(abs_json_dir_path_from)


# 帮忙完善这个函数
# def to_file_path_name(filename:str):
#     """
#     任何不适合在路径上产生的字符都改为下划线 比如 / \ : * ? " < > | 空格等
#     """
#     filename=filename.strip()
#     filename = filename.replace(" ", "_")
#     # https://www.cnblogs.com/jjliu/p/11514226.html
#     filename = filename.replace(":", "")
#     return filename

def to_file_path_name(filename: str) -> str:
    """
    将文件名中不适合用作路径名的字符替换为下划线

    Args:
        filename: 文件名字符串

    Returns:
        新的文件名字符串
    """
    invalid_chars = rf'\/:*?"<>| '  # 定义所有不合法字符
    for char in invalid_chars:
        filename = filename.replace(char, '_')  # 将不合法字符替换成下划线
    return filename.strip()  # 去除首尾空格并返回新的文件名字符串

# def read_file_chars(filename,from_idx=99,chars_len=200,encoding='utf-8'):
#     with open(filename, 'r',encoding=encoding) as file:
#         file.seek(from_idx)  # 将文件指针移动到第100个字符的位置
#         chars = file.read(chars_len)  # 读取接下来的200个字符
#     return chars

def read_file_chars(filename,chars_len=200,from_idx=0,encoding='utf-8'):
    with open(filename, 'r',encoding=encoding) as file:
        file.seek(from_idx)  # 将文件指针移动到第100个字符的位置
        chars = file.read(chars_len)  # 读取接下来的200个字符
    return chars

import os
# "utf-8"

# do_write=False
do_write=True
def create_file_with_directory(file_path,write_data,encoding=utf_8):
    if not do_write:
        return
    print(file_path)
    directory = os.path.dirname(file_path)  # 获取文件所在的目录
    if not os.path.exists(directory):
        os.makedirs(directory)  # 创建目录
    with open(file_path, 'w',encoding=encoding) as file:
        # 在这里写入文件内容
        file.write(write_data)

def check_and_create_file_parent_dir(file_path,):
    if not do_write:
        return
    # print("file_path",file_path)
    directory = os.path.dirname(file_path)  # 获取文件所在的目录
    if directory=='':
        return
    if not os.path.exists(directory):
        os.makedirs(directory)  # 创建目录

def check_and_makedirs(zip_file_out_path_base):
    if not os.path.exists(zip_file_out_path_base):
        os.makedirs(zip_file_out_path_base)

# taoBao

# "G:\movedAli\未命名1.cpp"
# "G:\多的\java高级\src.zip"
# "D:\weixinData\WeChat Files\wxid_6u05k4dt9r8e22\FileStorage\File\2023-05\新建文本文档.c"
# "D:\weixinData\WeChat Files\wxid_6u05k4dt9r8e22\FileStorage\File\2023-05\新建文件夹.zip"
# "D:\weixinData\WeChat Files\wxid_6u05k4dt9r8e22\FileStorage\File\2023-05\动画_2.fbx"
# "D:\weixinData\WeChat Files\wxid_6u05k4dt9r8e22\FileStorage\File\2023-05\动画.blend"
# "D:\weixinData\WeChat Files\wxid_6u05k4dt9r8e22\FileStorage\File\2023-05\动画.fbx"
# "D:\weixinData\WeChat Files\wxid_6u05k4dt9r8e22\FileStorage\File\2023-05\Untitled (1).ipynb"
# "D:\weixinData\WeChat Files\wxid_6u05k4dt9r8e22\FileStorage\File\2023-05\ruoyi.sql"
# "D:\weixinData\WeChat Files\wxid_6u05k4dt9r8e22\FileStorage\File\2023-05\hotel.sql"
# "D:\weixinData\WeChat Files\wxid_6u05k4dt9r8e22\FileStorage\File\2023-05\all_data.csv"
# "D:\weixinData\WeChat Files\wxid_6u05k4dt9r8e22\FileStorage\File\2023-05\bgm.mp3"
# "D:\weixinData\WeChat Files\wxid_6u05k4dt9r8e22\FileStorage\File\2023-06\apiclient_key.pem"
# "D:\weixinData\WeChat Files\wxid_6u05k4dt9r8e22\FileStorage\File\2023-06\application-prod.yaml"
# "G:\Download\后端.pdf"
# "G:\movedAli\未命名1.exe"
# "G:\movedAli\t_article.sql"
# "G:\movedAli\plan.sql"
# "D:\movedAli\demo-0.0.1-SNAPSHOT.jar"
# "G:\movedAli\zhihu.sql"
# "G:\movedAli\未命名-1.xd"
# "D:\weixinData\WeChat Files\wxid_6u05k4dt9r8e22\FileStorage\File\2023-06\Word.docx"
# "E:\movedAli\windows.zip"
# "E:\file\job.json"
# "E:\file\job.csv"
# "D:\download\download-image-py.ipynb"
# "E:\file\mongo.jpg"
# "E:\file\style.less"
# "E:\file\zhihu.png"
# "D:\movedAli\XML.zip"
# "E:\file\vant.png"
# "E:\file\phoneFIle.txt"
# "E:\file\newfit.sql"
# "E:\addd\movedAli\值.json"
# "E:\file\public.sql"
# "D:\movedAli\apiclient_key.pem"
# "E:\addd\movedAli\新建 Microsoft Excel 工作表.xlsx"
# "E:\addd\movedAli\下载 (1)"
# "E:\addd\movedAli\值.csv"
# "E:\addd\movedAli\未命名简历.pdf"
# "E:\addd\movedAli\未命名的设计.png"
# "E:\addd\movedAli\图片1.png"
# "E:\addd\movedAli\图标素材.json"
# "E:\addd\movedAli\Untitled.zip"
# "E:\addd\movedAli\后端工程师.pdf"
# "E:\addd\movedAli\缪奇鹏-Java.pdf"
# "E:\addd\movedAli\缪奇鹏 java开发.pdf"
# "E:\addd\movedAli\缪奇鹏.pptx"
# "E:\addd\movedAli\pwc.pdf"
# "E:\addd\movedAli\s (1).png"
# "E:\addd\movedAli\nginx.conf"
# "D:\download\apiclient_cert.p12"
# "D:\movedAli\github_search.json"

# "D:\movedAli\WalkTwo.json"
# "D:\movedAli\issues.json"
# "D:\movedAli\creators_civitai_get_pages.json"
# "D:\movedAli\creators_civitai_get.json"
# "E:\movedAli\sql.txt"
# "E:\movedAli\out.html"
# "E:\movedAli\out.mhtml"
# "E:\movedAli\国奖.mp4"
# "E:\movedAli\工作簿1.xlsx"
# "E:\movedAli\工作簿4.xlsx"
# "E:\movedAli\Title.pdf"
# "E:\movedAli\附件2.docx"
# "E:\movedAli\README.md"
# "E:\movedAli\src.rar"
# "E:\movedAli\未命名-2.xd"
# "E:\movedAli\sql.txt"
# "E:\movedAli\Title.pdf"
"E:\movedAli\main.cpp"
import re

# 放到list re_lst 是类似他的
def get_src_dst_list_re(src, dst, src_lst: list, dst_lst: list,
                        ignore_dir_lst: list, re_lst):
    lsdir = os.listdir(src)
    dirs = [i for i in lsdir if os.path.isdir(os.path.join(src, i))]

    if dirs:
        for dir in dirs:
     
            if dir in ignore_dir_lst:
                continue
         
            get_src_dst_list_re(os.path.join(src, dir),
                                os.path.join(dst, dir), src_lst,
                                dst_lst, ignore_dir_lst, re_lst)
            # dst  也相应的 增加 后面的 后缀
            # 深入一层

    files = [i for i in lsdir if os.path.isfile(os.path.join(src, i))]
    # idx = 0
    for f in files:
        # 文件名字 像什么
        # print("f", f)
        if re_lst is None:
            # 如果是 none 的话，就不管什么样子都放进去了
            abs_path = os.path.join(src, f)
            abs_path_dst = os.path.join(dst, f)
  
            src_lst.append(abs_path)
            dst_lst.append(abs_path_dst)
            continue

        for re_str in re_lst:
            if re.search(re_str, f):
                # if "大纲" not in f:
                #     continue
                abs_path = os.path.join(src, f)
                abs_path_dst = os.path.join(dst, f)
         
                src_lst.append(abs_path)
                dst_lst.append(abs_path_dst)



# from shutil import copyfile

import shutil
# https://blog.csdn.net/qq_42455710/article/details/88861296
def copy_file_force(src, dst):
    dst_dirname = os.path.dirname(dst)
    if not os.path.exists(dst_dirname):
        os.makedirs(dst_dirname)
    # os.makedirs(dst_dirname)
    shutil.copyfile(src, dst)

def copy_file_not_cover(src, dst):
    if os.path.exists(dst):
        print("已经存在", dst)
        return
    copy_file_force(src, dst)

def copyfile_lst(src_lst, dst_lst):
    idx = 0
    for src in src_lst:
        dst = dst_lst[idx]
        copy_file_not_cover(src, dst)
        idx += 1


def backup_proj_src(proj_path = r"G:\project\react\AwesomeProject",dst_path = r"G:\project\react\AwesomeBasketball"
,ignore_dir_lst = ["dist", "node_modules", ".git", ".idea","out","target","build","backup","sql","release",
"unpackage","htmlStable","static"],re_lst = ["\.doc$"]):
   
    # dst_path = r"G:\project\javaProj\gaoji_back"
    file_lst = []
    dst_lst = []
    # ignore_dir_lst = ["dist", "node_modules", ".git", ".idea","out","target","build","backup","sql","release"]

    ignore_filename_lst = ["dist (5).zip"]
    # re_lst = ["\.java$"]
    # re_lst = None
    # 所有文件都查找
    # re_lst = [".java$"]
    # 符合 这个re 的查找

    like_str_list = ["zip", "js"]
    
    get_src_dst_list_re(proj_path, dst_path, file_lst, dst_lst,
                        ignore_dir_lst, re_lst)
    print("file_lst", file_lst)
    print("dst_lst", dst_lst)
    copyfile_lst(file_lst,dst_lst)
    print("back up at",dst_path)

# def 
# key_word in file_name
def key_word_in(file_name):
    for key_word in check_list:
        if key_word in file_name:
            return True
    return False

def file_name_in(file_name):
    for key_word in check_list:
        if key_word == file_name:
            return True
    return False

try:
    from top.starp.util import time_util

except Exception as e:
    import time_util

import shutil
import os

def delete_node_modules(directory):
    node_modules_path = os.path.join(directory, 'node_modules')
    if os.path.exists(node_modules_path):
        try:
            shutil.rmtree(node_modules_path)
            print(f"Deleted 'node_modules' directory at {node_modules_path}")
        except Exception as e:
            print(f"Error while deleting 'node_modules': {e}")
    else:
        print("The 'node_modules' directory does not exist.")

# # 指定需要删除 'node_modules' 的目录路径
# target_directory = '/path/to/your/project'

# delete_node_modules(target_directory)



def filename_删掉括号(filename = "kaggle_code_https___www.kaggle.com_code_mikufance_anything-v3-0-gen (4).html"):
    # filename = "kaggle_code_https___www.kaggle.com_code_mikufance_anything-v3-0-gen (4).html"

    # 找到括号的位置
    start_index = filename.find("(")
    end_index = filename.find(")")

    # 去掉括号及其内部的内容，并去掉前面的空格
    # new_filename = filename[:start_index-1] + filename[end_index+1:]
    new_filename = filename[:start_index] + filename[end_index+1:]
    new_filename=new_filename.strip()

    # print(new_filename)
    return new_filename


def ali_may_not_save(dir_name=rf"E:\addd\movedAli",sameName_dir=rf"E:\addd\sameName"):
    now_time_str=time_util.get_now_time_str()

    sameName_dir_now=os.path.join(sameName_dir,f"same_name_{now_time_str}")
    # import 
    for file_name in os.listdir(dir_name):
        # if file_name in 
        if file_name_in(file_name):
            abs_path=os.path.join(dir_name,file_name)
            print(abs_path)
            same_name_file=os.path.join(sameName_dir_now,file_name)
            print(same_name_file)
            check_and_move_file(abs_path,same_name_file)
            # file_util.check_and_move_file(abs_path,same_name_file)


# # 示例使用
# file_path = '/path/to/directory/file.txt'  # 文件路径
# create_file_with_directory(file_path)


def convert_size(size_bytes):
    # 转换单位函数
    units = ["bytes", "KB", "MB", "GB", "TB"]
    unit_index = 0
    while size_bytes >= 1024 and unit_index < len(units) - 1:
        size_bytes /= 1024
        unit_index += 1
    size_formatted = f"{size_bytes:.2f} {units[unit_index]}"
    return size_formatted

# 调用示例
# filename = 'path/to/your/file.txt'  # 替换为你的文件路径
# result = read_file_chars(filename)
# print(result)

import zipfile
import os

def zip_folder(folder_path, zip_path):
    with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
        for root, _, files in os.walk(folder_path):
            for file in files:
                file_path = os.path.join(root, file)
                zipf.write(file_path, os.path.relpath(file_path, folder_path))
import shutil
def rmtree(dir_name_base):
    shutil.rmtree(dir_name_base)

import logging
import requests

def download_image(url, save_path):
    return download_file(url=url,save_path=save_path)
    # check_and_create_file_parent_dir(save_path)
    # response = requests.get(url,timeout=10)
    # if response.status_code == 200:
    #     with open(save_path, 'wb') as file:
    #         file.write(response.content)
    #     # print('图片下载完成！')
    # else:
    #     print('图片下载失败！url',url,'save_path',save_path,"response",response)
    #     pass


    # try:
    #     download_image_try(url, save_path)
    # except Exception as e:
    #     print("err url ",url,"save_path",save_path)
    #     print(e)
    #     # ll 
    #     logging.exception(e)
    #     raise e


def download_file(url, save_path):
    try:
        download_file_try(url, save_path)
    except Exception as e:
        print("err url ",url,"save_path",save_path)
        print(e)
        logging.exception(e)
        raise e


def download_image_try(url, save_path,timeout=30):
    return download_file_try(url, save_path,timeout=timeout)
    # check_and_create_file_parent_dir(save_path)
    # response = requests.get(url,timeout=timeout)
    # if response.status_code == 200:
    #     with open(save_path, 'wb') as file:
    #         file.write(response.content)
    #     # print('图片下载完成！')
    # else:
    #     print('图片下载失败！url',url,'save_path',save_path,"response",response)
    #     pass

def download_file_try(url, save_path,timeout=30):
    check_and_create_file_parent_dir(save_path)
    response = requests.get(url,timeout=timeout)
    if response.status_code == 200:
        with open(save_path, 'wb') as file:
            file.write(response.content)
    else:
        print('文件下载失败！url',url,'save_path',save_path,"response",response)
        pass


# https://pic1.zhimg.com/80/v2-d212e332ba2905e907f406198dbf20a4_1440w.webp
def download_one_img(image_url,save_dir=rf"/kaggle/working/file/imgs"):
    file_name=image_url.split('/')[-1]
    # save_path = rf'D:\file/image.jpg'
    # save_dir=rf"D:\file/imgs"
    # save_dir=rf"file/imgs"

    # file_util.cre 
    if not os.path.exists(save_dir):
        os.makedirs(save_dir,exist_ok=True)

    save_path=os.path.join(save_dir,file_name)
    # save_path
    # D:\proj\python\st-util\download_image.py
    download_image(image_url, save_path)


def download_one_file(image_url,save_dir=rf"/kaggle/working/file/imgs"):
    file_name=image_url.split('/')[-1]
    if not os.path.exists(save_dir):
        os.makedirs(save_dir,exist_ok=True)

    save_path=os.path.join(save_dir,file_name)
    download_file(image_url, save_path)


# # 要下载的图片URL
# image_url = 'https://example.com/image.jpg'
# # 保存图片的路径和文件名
# save_path = 'path/to/save/image.jpg'

# # 调用函数下载图片
# download_image(image_url, save_path)


def scrawl_file_move(from_dir_name=rf"D:\download",batch_files_dir=rf"D:\file\batch_files"):
    # D:\file\batch_files
    
    # from_dir_name=rf"D:\download"
    # "E:\原来的\taobao_java_2023_1_3_13_32_45.json"
    # E:\原来的
    
    starts_with_file_json_move(dir_name=rf"E:\addd\movedAli",to_dir_name=rf"D:\taobao",startswith="taobao_")
    starts_with_file_json_move(dir_name=rf"E:\原来的",to_dir_name=rf"D:\taobao",startswith="taobao_")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\taobao",startswith="taobao_")
    # "D:\download\zhihu_ans_代写真的会去举报学校吗_.json"
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\zhihu_ans",startswith="zhihu_ans_")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\boss_detail",startswith="boss_detail_")
    # "D:\download\boss_detail_828e2bb32bdae73f1n190960GVFS_idx_0 (1).json"
    # "D:\download\wget_https___gitee.com_starplatinum111_GenerateQRCode.sh"
    # "D:\download\nowcoderAns_idx_2 (3).json"
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\school_24",startswith="school_24_")
    # "D:\download\school_24_detail_PyYWMZpPnznggP7MGhCUkW_idx_18.json"
    # "D:\download\nowcoder (99).json"
    # "D:\download\nowcoderAns (5).json"
    
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\school_24",startswith="school_24_")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\nowcoderAns",startswith="nowcoderAns")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\nowcoder",startswith="nowcoder")
    # starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\wget_https",startswith="wget_https__")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\wget_https",startswith="wget_https__")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\kaoBianLinkGet",startswith="kaoBianLinkGet")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\zhiHuGet",startswith="zhiHuGet")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\fangTianXia",startswith="fangTianXia")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\xhs_https",startswith="xhs_https")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\我爱我家_https",startswith="我爱我家_https")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\链家_https",startswith="链家_https")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\xhs_note",startswith="xhs_note")
    # "D:\download\链家_https___hz.lianjia.com_zufang_rs%E6%96%B0%E5%AE%89%E5%A4%A9%E8%8B%91_.json"
    # "D:\download\xhs_note_https___www.xiaohongshu.com_explore_646b60730000000013032b65.json"
    # "D:\download\我爱我家_https___hz.5i5j.com_zufang_o3__%E7%BB%BF%E5%9F%8E%E8%BF%90%E6%B2%B3%E9%83%A1_.json"
    # "D:\download\xhs_https___www.xiaohongshu.com_explore_keyword=java (2).json"
    # "D:\download\fangTianXia_https___hz.zu.fang.com_house_i32-s31-kw%b9%cf%c9%bd_.json"
    # "D:\download\zhiHuGet_常用的后端开发语言有哪些？.json"
    # starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\douBanHtml",startswith="douBanHtml")
    # starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\bilibili_html",startswith="https___www.bilibili")
    # "D:\download\kaoBianLinkGet_undefined (7).json"
    # "D:\download\https___www.bilibili.com_correspond_1_a8f25574ed7d12e7e0d5a0149c81910c249523e12fce31c5f65413a419313d527bd9c783e34793fc58e51772cb7421e3250415f3cf5797f56c0db29f13de67462270467497d07447dac0ce80ee41795fd1c8a44921a2d1a4f92a3530a4b1.html"
    # "D:\download\douBanHtml_https___movie.douban.com_subject_35213072__from=subject-page.html"
    file_like_move(from_dir_name=rf"D:\download",to_dir_name=rf"D:\wget_https",startswith="wget_https__",ends_with=".sh")
    file_like_move(from_dir_name=rf"D:\download",to_dir_name=rf"D:\bilibili_html",startswith="https___www.bilibili",ends_with=".html")
    file_like_move(from_dir_name=rf"D:\download",to_dir_name=rf"D:\douBanHtml",startswith="douBanHtml",ends_with=".html")
    file_like_move(from_dir_name=rf"D:\download",to_dir_name=rf"D:\csdn_https",startswith="csdn_https",ends_with=".html")
    # "D:\download\csdn_https___blog.csdn.net_m0_47096428_article_details_129293259.html"
    # "D:\download\zhihuArticle_https___zhuanlan.zhihu.com_p_606877530.html"
    # "D:\download\hugDownKaggle_JamesFlare_pastel-mix (9).sh"
    # "D:\download\hugDownWin_Linaqruf_anything-v3.0.txt"
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf"D:\hugDownWin",startswith="hugDownWin",ends_with=".txt")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf"D:\hugDownKaggle",startswith="hugDownKaggle",ends_with=".sh")
    # "D:\movedAli\kaggle_code_https___www.kaggle.com_code_mikufance_anything-v5_log_scriptVersionId=133869288.html"
    # "D:\download\kaggle_code_https___www.kaggle.com_code_mikufance_anything-v5-stablediffusionpipeline_scriptVersionId=133886765 (1).html"
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf"D:\zhihuArticle",startswith="zhihuArticle",ends_with=".html")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf"D:\kaggle_code",startswith="kaggle_code",ends_with=".html")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf"D:\hugDown",startswith="hugDown",ends_with=".txt")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf"D:\zhihu_shouye",startswith="zhihu_shouye",ends_with=".html")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf"{batch_files_dir}/baidu",startswith="baidu_",ends_with=".html")
    # "D:\movedAli\baidu_https___www.baidu.com_s_tn=02003390_42_hao_pg&wd=com.mysql.jdbc.exceptions.jdbc4.CommunicationsException%3A+Communications+link+failure&ie=utf-8.html"
    # file_like_move(from_dir_name=from_dir_name,to_dir_name=rf"D:\bingDown",startswith="bingDown",ends_with=".html")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf"{batch_files_dir}/bingDown",startswith="bingDown",ends_with=".html")
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/taobao',startswith="taobao",ends_with=".json")
    # "D:\download\zhihu_shouye_https___www.zhihu.com_ (2).html"
    file_like_move(from_dir_name=from_dir_name,to_dir_name=rf'{batch_files_dir}/huggingface_main',startswith="huggingface_main",ends_with=".html")
    # "G:\多的\taobao_洗发水_2023_1_4_9_34_25.json"
    # "D:\download\huggingface_main_https___huggingface.co_models_search=from%20diffusers.html"
    # "D:\download\hugDown_JamesFlare_pastel-mix (17).txt"
    # bingDown
    # "D:\download\kaggle_code_https___www.kaggle.com_code_mikufance_download-image-py (5).html"
    # "D:\download\zhihu_shouye_https___www.zhihu.com_ (9).html"


# shutil.rmtree(dir_name_base)
# 示例用法
# folder_path = r'C:\path\to\folder'  # 要压缩的文件夹路径
# zip_path = r'C:\path\to\output.zip'  # 压缩后的zip文件路径

# zip_folder(folder_path, zip_path)


if __name__ == "__main__":

    # "D:\好活.txt"
    # move_file("D:\好活.txt",rf"D:\file")
    # file 
    # data=read_file("D:\好活.txt")
    # print(data)
    # abs_path_list=getAllFilesOfWalk(rf"D:\毕设")
    # for i in abs_path_list:
    #     print(i)
    # dir_name=rf"D:\download"
    # to_dir_name=rf"D:\taoBao"
    # taoBao_dir_name=rf"D:\taoBao"
    # # for i in os.listdir(dir_name):
    # #     # "D:\taoBao\taobao_ 杏仁_2023_2_6_8_43_5.json"
    # #     if i.startswith("taobao") and i.endswith(".json"):
    # #         abs_from_file=os.path.join(dir_name,i)
    # #         abs_to_file=os.path.join(to_dir_name,i)
    # #         shutil.move(abs_from_file,abs_to_file)  
    # #         # move_file(abs_from_dir,abs_to_dir)
    # #         # D:\taoBao

    # # D:\taoBaoOut
    # taoBaoOut_dir_name=rf"D:\taoBaoOut"
    # # 'D:\\taoBao\\taobao_ 杏仁_2023_3_18_8_47_21.json'
    # # res=os.removedirs('D:\\taoBao\\taobao_ 杏仁_2023_3_18_8_47_21.json')
    # # print("res",res)
    # for i in os.listdir(taoBao_dir_name):
    #     # if 
    #     # print(i)
    #     abs_json_dir_path_from=os.path.join(taoBao_dir_name,i)
        
    #     if os.path.isdir(abs_json_dir_path_from):
    #         abs_json_path=os.path.join(taoBao_dir_name,i,i)
    #         abs_json_path_to=os.path.join(taoBaoOut_dir_name,i)
    #         # shutil.move(abs_json_path,abs_json_path_to)  
    #         # print("abs_json_path",)
    #         # print(abs_json_path,abs_json_path_to)
    #         # os.remove(abs_json_dir_path_from)
    #         # os.remove(abs_json_dir_path_from)
    #         os.removedirs(abs_json_dir_path_from)
    #         print(abs_json_dir_path_from)

    # taoBao_json_move()
    # "D:\download\boss_detail_c38f11dd2d850c331XVz2d20E1NQ_idx_7.json"
    # "D:\download\zhiPin_page_1_python爬虫工程师.json"
    # starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\zhiPin_page",startswith="zhiPin_page")
    # starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\boss_detail",startswith="boss_detail")
    # "D:\download\24265_school_page_16.json"
    # sch_24_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\24detail",startswith="school_24")
    # starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\24Ddata",startswith="24265_school")
    # starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\kanZhunSalary",startswith="kanZhunSalary")
    # "D:\download\kanZhunSalary_https___www.kanzhun.com_firm_wage_0nxz2Nu4FVA~.html_idx=128.json"
    # look_front('D:\i-brain\ins_list/nowcoderAns_content_summary_2023_05_16_15_06_46.json')
    
    
    # front_chars=read_file_chars(rf'D:\i-brain\ins_list/nowcoderAns_content_summary_2023_05_16_15_06_46.json',from_idx=330)
    # pprint.pprint(front_chars)
    # "D:\download\nowcoder - 2023-05-29T114557.110.json"
    # python D:\proj\python\my_util_py_pub\file_util.py
    # "D:\BaiduSyncdisk\zhiHuGet_如何进行职业规划与职业发展？.json"
    # starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\nowCoderFile",startswith="nowcoder - ")
    # starts_with_file_json_move(dir_name=rf"D:\BaiduSyncdisk",to_dir_name=rf"D:\zhiHuGetJson",startswith="zhiHuGet_")
    # "D:\BaiduSyncdisk\kaoBianLinkGet_undefined (18).json"
    # "D:\BaiduSyncdisk\zhihu_ans_五分钟的毕业设计答辩需要写哪些内容？.json"
    # "D:\BaiduSyncdisk\taobao_python_2023_5_12_9_3_15.json"
    # starts_with_file_json_move(dir_name=rf"D:\BaiduSyncdisk",to_dir_name=rf"D:\kaoBianLink",startswith="kaoBianLinkGet_")
    # starts_with_file_json_move(dir_name=rf"D:\BaiduSyncdisk",to_dir_name=rf"D:\zhihu_ans",startswith="zhihu_ans")
    # starts_with_file_json_move(dir_name=rf"D:\BaiduSyncdisk",to_dir_name=rf"D:\taobao",startswith="taobao_")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\taobao",startswith="taobao_")
    # "D:\download\zhihu_ans_代写真的会去举报学校吗_.json"
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\zhihu_ans",startswith="zhihu_ans_")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\boss_detail",startswith="boss_detail_")
    # "D:\download\boss_detail_828e2bb32bdae73f1n190960GVFS_idx_0 (1).json"
    # "D:\download\wget_https___gitee.com_starplatinum111_GenerateQRCode.sh"
    # "D:\download\nowcoderAns_idx_2 (3).json"
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\school_24",startswith="school_24_")
    # "D:\download\school_24_detail_PyYWMZpPnznggP7MGhCUkW_idx_18.json"
    # "D:\download\nowcoder (99).json"
    # "D:\download\nowcoderAns (5).json"
    
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\school_24",startswith="school_24_")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\nowcoderAns",startswith="nowcoderAns")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\nowcoder",startswith="nowcoder")
    # starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\wget_https",startswith="wget_https__")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\wget_https",startswith="wget_https__")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\kaoBianLinkGet",startswith="kaoBianLinkGet")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\zhiHuGet",startswith="zhiHuGet")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\fangTianXia",startswith="fangTianXia")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\xhs_https",startswith="xhs_https")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\我爱我家_https",startswith="我爱我家_https")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\链家_https",startswith="链家_https")
    starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\xhs_note",startswith="xhs_note")
    # "D:\download\链家_https___hz.lianjia.com_zufang_rs%E6%96%B0%E5%AE%89%E5%A4%A9%E8%8B%91_.json"
    # "D:\download\xhs_note_https___www.xiaohongshu.com_explore_646b60730000000013032b65.json"
    # "D:\download\我爱我家_https___hz.5i5j.com_zufang_o3__%E7%BB%BF%E5%9F%8E%E8%BF%90%E6%B2%B3%E9%83%A1_.json"
    # "D:\download\xhs_https___www.xiaohongshu.com_explore_keyword=java (2).json"
    # "D:\download\fangTianXia_https___hz.zu.fang.com_house_i32-s31-kw%b9%cf%c9%bd_.json"
    # "D:\download\zhiHuGet_常用的后端开发语言有哪些？.json"
    # starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\douBanHtml",startswith="douBanHtml")
    # starts_with_file_json_move(dir_name=rf"D:\download",to_dir_name=rf"D:\bilibili_html",startswith="https___www.bilibili")
    # "D:\download\kaoBianLinkGet_undefined (7).json"
    # "D:\download\https___www.bilibili.com_correspond_1_a8f25574ed7d12e7e0d5a0149c81910c249523e12fce31c5f65413a419313d527bd9c783e34793fc58e51772cb7421e3250415f3cf5797f56c0db29f13de67462270467497d07447dac0ce80ee41795fd1c8a44921a2d1a4f92a3530a4b1.html"
    # "D:\download\douBanHtml_https___movie.douban.com_subject_35213072__from=subject-page.html"
    file_like_move(from_dir_name=rf"D:\download",to_dir_name=rf"D:\wget_https",startswith="wget_https__",ends_with=".sh")
    file_like_move(from_dir_name=rf"D:\download",to_dir_name=rf"D:\bilibili_html",startswith="https___www.bilibili",ends_with=".html")
    file_like_move(from_dir_name=rf"D:\download",to_dir_name=rf"D:\douBanHtml",startswith="douBanHtml",ends_with=".html")
    file_like_move(from_dir_name=rf"D:\download",to_dir_name=rf"D:\csdn_https",startswith="csdn_https",ends_with=".html")
    # D:\jsonFile
    # file_like_move(from_dir_name=rf"D:\download",to_dir_name=rf"D:\csdn_https",startswith="csdn_https",ends_with=".html")
    # "D:\download\csdn_https___blog.csdn.net_m0_47096428_article_details_129293259.html"

    scrawl_file_move()